﻿$devices = Get-WmiObject -Class Win32_PnPEntity

# 创建结果数组
$results = @()

foreach ($device in $devices) {
    $deviceInfo = @{
        "DeviceName" = $device.Name
        "PNPDeviceID" = $device.PNPDeviceID
        "Status" = $device.Status
        "ConfigManagerErrorCode" = $device.ConfigManagerErrorCode
    }
    $results += New-Object PSObject -Property $deviceInfo
}

# 可选：导出到 CSV 文件
$results | Export-Csv -Path "PnPDevices.csv" -NoTypeInformation -Encoding UTF8